package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.mapper.AlbumInfoMapper;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;
    @Autowired
    private AlbumInfoMapper albumInfoMapper;


	@Operation(summary = "分类管理")
	@GetMapping("/getBaseCategoryList")
	public Result getBaseCategroyList(){
		List<JSONObject> list=baseCategoryService.getBaseCategroyList();
		return Result.ok(list);
	}

	@Operation(summary = "根据一级分类Id获取属性与属性值数据")
	@GetMapping("/findAttribute/{category1_id}")
	public Result findAttribute(@PathVariable("category1_id") Long category1Id){
		List<BaseAttribute> baseAttributes=baseCategoryService.findAttribute(category1Id);
		return Result.ok(baseAttributes);
	}


	/**
	 * 根据三级分类Id获取分类对象
	 * @param category3_id
	 * @return
	 */
	@Operation(summary = "根据三级分类Id获取分类对象")
	@GetMapping("/getCategoryView/{category3Id}")
	public Result<BaseCategoryView> getCategoryView(@PathVariable Long category3Id){
		BaseCategoryView baseCategoryView=baseCategoryService.getCategoryView(category3Id);
		return Result.ok(baseCategoryView);
	}

	/**
	 * 根据一级分类Id获取全部分类信息
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据一级分类Id查询一级分类对象")
	@GetMapping("/getBaseCategoryList/{category1Id}")
	public Result getBaseCategoryList(@PathVariable Long category1Id){
		JSONObject category1 = baseCategoryService.getBaseCategoryList(category1Id);
		return Result.ok(category1);
	}

	/**
	 * 根据一级分类Id查询一级分类对象
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据一级分类Id查询置顶到频道页的三级分类列表")
	@GetMapping("/findTopBaseCategory3/{category1Id}")
	Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable Long category1Id){
		List<BaseCategory3> baseCategory3List =baseCategoryService.findTopBaseCategory3(category1Id);
		return Result.ok(baseCategory3List);
	}

	/**
	 * 查询所有一级分类
	 * @return
	 */
	@Operation(summary = "查询所有一级分类")
	@GetMapping("/findAllCategory1")
	Result<List<BaseCategory1>> findCategory1All(){
		List<BaseCategory1> baseCategory1List =baseCategoryService.findCategory1All();
		return Result.ok(baseCategory1List);
	}
}

